from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QVBoxLayout
import sys

class static:
    step = 0
num = static()

def btn1_cb():
    print("含有边框的坐标:")
    print("widget.x() = %d" % widget.x())
    print("widget.y() = %d" % widget.y())
    print("widget.height() = %d" % widget.height())
    print("widget.width() = %d" % widget.width())
    print("不含边框工作区的坐标:")
    print("widget.geometry().x() = %d" % widget.geometry().x())
    print("widget.geometry().y() = %d" % widget.geometry().y())
    print("widget.geometry().height() = %d" % widget.geometry().height())
    print("widget.geometry().width() = %d" % widget.geometry().width())
    print("窗口的坐标:")
    print("widget.frameGeometry().x() = %d" % widget.frameGeometry().x())
    print("widget.frameGeometry().y() = %d" % widget.frameGeometry().y())
    print("widget.frameGeometry().height() = %d" % widget.frameGeometry().height())
    print("widget.frameGeometry().width() = %d" % widget.frameGeometry().width())

def btn2_cb(widget):
    if num.step == 0:
        widget.move(0,0)
        num.step += 1
    elif num.step == 1:
        widget.move(379,600)
        num.step += 1
    elif num.step == 2:
        widget.move(879,600)
        num.step += 1
    elif num.step == 3:
        widget.move(879,800)
        num.step = 0



app = QApplication(sys.argv)
widget = QWidget()
btn1 = QPushButton(widget)
btn1.setText("这是第一个按钮")
btn2 = QPushButton(widget)
btn2.setText("这是第二个按钮")
layout = QVBoxLayout()
layout.addWidget(btn1)
layout.addWidget(btn2)
btn1.clicked.connect(btn1_cb)
btn2.clicked.connect(lambda: btn2_cb(widget))
widget.setLayout(layout)
widget.resize(250, 200)
widget.move(250, 200)
widget.setWindowTitle("面向过程创建GUI")
widget.show()
sys.exit(app.exec_())




